package com.lei.web;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CarServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		Map<String, List<String>> data = new HashMap<String, List<String>>();
		List<String> bmwList = new ArrayList<String>();
		bmwList.add("521");
		bmwList.add("621");
		bmwList.add("721");
		bmwList.add("821");
		
		List<String> audiList = new ArrayList<String>();
		audiList.add("A1");
		audiList.add("A2");
		audiList.add("A3");
		audiList.add("A4");
		audiList.add("A5");
		audiList.add("A6");
		
		List<String> benzList = new ArrayList<String>();
		benzList.add("B1");
		benzList.add("B2");
		benzList.add("B3");
		benzList.add("B4");
		
		data.put("bmw", bmwList);
		data.put("audi", audiList);
		data.put("benz", benzList);	
		
		String name = request.getParameter("name");	
		List<String> dataList = data.get(name);	
		response.setContentType("text/xml;charset=UTF-8");
		PrintWriter out = response.getWriter();
		out.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		out.print("<data>");
		for(String str : dataList) {
			out.print("<recode>"+str+"</recode>");
		}
		out.print("</data>");
		
		out.flush();
		out.close();
		
		
	}

}
